<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <style>
        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }

        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>预约管理
            <small>预约列表</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>预约管理</el-breadcrumb-item>
            <el-breadcrumb-item>预约列表</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input placeholder="档案号/姓名/手机号" v-model="pagination.queryString" style="width: 200px;"
                          class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                <el-button @click="findPage1()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
            </div>
            <template>
                <el-table
                        current-row-key="id"
                        ref="multipleTable"
                        :data="dataList"
                        tooltip-effect="dark"
                        style="width: 100%"
                        :row-key="handleReserve"
                        @selection-change="handleSelectionChange">
                    <el-table-column
                            type="selection"
                            width="55"
                            prop="id"
                            :selectable="checkboxlnit"
                            reserve-selection
                            @selection-change="handleSelectionChange"
                            >
                    </el-table-column>
                    <el-table-column
                            label="预约日期"
                            width="200"
                            prop="orderDate">
                    </el-table-column>
                    <el-table-column
                            prop="fileNumber"
                            label="档案号"
                            width="160">
                    </el-table-column>
                    <el-table-column
                            prop="name"
                            label="姓名"
                            width="120">
                    </el-table-column>
                    <el-table-column
                            prop="phoneNumber"
                            label="手机号码"
                            sortable
                            width="160">
                    </el-table-column>
                    <el-table-column
                            prop="orderType"
                            label="预约类型"
                            sortable
                            width="160">
                    </el-table-column>
                    <el-table-column
                            prop="orderStatus"
                            label="预约状态"
                            width="120">
                    </el-table-column>
                    <el-table-column label="操作" align="center">
                        <template slot-scope="scope">
                            <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">确认预约</el-button>
                            <el-button size="mini" type="danger" @click="handleDelete(scope.row)">取消预约</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <div>
                    <el-button type="primary" size="mini" @click="batchhandleUpdate()">一键确认</el-button>
                    <el-button size="mini" type="danger" @click="batchhandleDelete()">一键取消</el-button>
                </div>
            </template>

            <!--分页条-->
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增" :visible.sync="dialogFormVisible">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right" label-width="100px">
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="姓名">
                                                <el-input v-model="formData.name"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="20">
                                            <el-form-item label="身份证">
                                                <el-input v-model="formData.idCard"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="16">
                                            <el-form-item label="出生日期">
                                                <el-date-picker
                                                        v-model="formData.birthday"
                                                        type="date"
                                                        placeholder="选择日期"
                                                        format="yyyy 年 MM 月 dd 日"
                                                        value-format="yyyy-MM-dd">
                                                </el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="16">
                                            <el-form-item label="手机号">
                                                <el-input v-model="formData.phoneNumber"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="性别">
                                                <el-select v-model="formData.sex">
                                                    <el-option label="不限" value="0"></el-option>
                                                    <el-option label="男" value="1"></el-option>
                                                    <el-option label="女" value="2"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="年龄">
                                                <el-input v-model="formData.age"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="婚姻状态">
                                                <el-input v-model="formData.remark"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="预约时间">
                                                <el-date-picker
                                                        v-model="formData.orderDate"
                                                        type="date"
                                                        placeholder="选择日期"
                                                        format="yyyy 年 MM 月 dd 日"
                                                        value-format="yyyy-MM-dd">
                                                </el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                            <el-tab-pane label="检查套餐" name="second">
                                <div class="filter-container">
                                    <el-input placeholder="检测套餐" v-model="setmealpagination.queryString" style="width: 200px;"
                                              class="filter-item"></el-input>
                                    <el-button @click="findPage2()" class="dalfBut">检测套餐</el-button>
                                </div>
                                <el-table
                                        ref="singleTable"
                                        :data="setmealdataList"
                                        highlight-current-row
                                        @current-change="setmealCurrentChange"
                                        style="width: 100%"
                                        prop="id">
                                    <el-table-column prop="name"
                                                     label="套餐名称"
                                                     align="center">

                                    </el-table-column>
                                    <el-table-column label="适用人群"
                                                     align="center">
                                        <template slot-scope="scope">
                                            <span>
                                                {{ scope.row.sex == '0' ? '不限' : scope.row.sex == '1' ? '男' : '女'}}
                                            </span>
                                        </template>
                                    </el-table-column>
                                    <el-table-column prop="remark"
                                                     label="套餐介绍"
                                                     align="center">
                                    </el-table-column>

                                </el-table>
                                <div class="pagination-container">
                                    <el-pagination
                                            class="setmealpagination"
                                            @current-change="setmealhandleCurrentChange"
                                            :current-page="setmealpagination.currentPage"
                                            :page-size="setmealpagination.pageSize"
                                            layout="total, prev, pager, next, jumper"
                                            :total="setmealpagination.total">
                                    </el-pagination>
                                </div>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">保存</el-button>
                    </div>
                </el-dialog>
            </div>

        </div>
    </div>
</div>
</body>

<script>
    var vue = new Vue({
        el: '#app',
        data: {
            activeName: 'first',//添加/编辑窗口Tab标签名称
            //预约页面分页查询
            pagination: {//分页相关属性
                currentPage: 1,
                pageSize: 10,
                total: 100,
                queryString: null,
            },
            //套餐页面分页查询
            setmealpagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize: 10,//每页显示的记录数
                total: 0,//总记录数
                queryString: null//查询条件
            },
            orderIds:[],//预约界面多选框
            dataList: [],//预约界面列表数据
            setmealdataList:[],//套餐界面列表数据
            formData: {},//表单数据
            tableData: [],//新增表单中对应的套餐列表数据
            setmealid: null,//新增表单中套餐对应的单选框，基于双向绑定可以进行回显和数据提交
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            dialogFormVisible4Edit: false,//控制编辑窗口显示/隐藏
            rules: {//校验规则
                name: [{required: true, message: '姓名不能为空', trigger: 'blur'}],
                sex: [{required: true, message: '性别不能为空', trigger: 'blur'}],
                age: [{required: true, message: '年龄不能为空', trigger: 'blur'}]

            }
        },
        created() {
            this.findPage();
        },
        methods: {
            //预约页面查询用
            findPage1() {
                this.pagination.currentPage = 1;
                this.findPage();
            },
            //套餐页面查询用
            findPage2(){
                this.setmealpagination.currentPage = 1;
                this.setmealfindPage();
            },
            //添加
            handleAdd() {
                //校验表单
                this.$refs['dataAddForm'].validate((valid)=>{
                    if(valid){
                        //发送ajax请求 将表单数据提交到后台进行处理
                        axios.post("/ordersetting/add.do?setmealid="+ this.setmealid, this.formData).then((res) => {
                            //关闭新增窗口
                            this.dialogFormVisible = false;
                            if (res.data.flag) {
                                //操作成功
                                this.$message({
                                    type: 'success',
                                    message: res.data.message
                                });
                            } else {
                                //操作失败
                                this.$message.error(res.data.message);
                            }
                        }).finally(() => {
                            //重新进行分页查询
                            this.findPage();
                            this.setmealid = [];
                        })
                    }else {
                        // 表单校验不通过
                        this.$message.error("数据校验失败,请检查你的表单");
                    }

                })
            },
            //预约页面分页查询
            findPage() {
                //封装分页参数
                var param = {
                    currentPage: this.pagination.currentPage,//当前页码
                    pageSize: this.pagination.pageSize,//每页显示的记录数
                    queryString: this.pagination.queryString//查询条件
                };
                //发送ajax请求 提交分页相关参数
                axios.post("/ordersetting/findOrdersPage.do", param).then((res) => {
                    //为VUE对象的模型数据赋值,基于双向数据绑定展示到页面
                    this.dataList = res.data.rows;//当前页展示的数据集合
                    this.pagination.total = res.data.total;//总数据量
                });
            },
            //套餐页面分页查询
            setmealfindPage(){
                //封装分页参数
                var param = {
                    currentPage: this.setmealpagination.currentPage,//当前页码
                    pageSize: this.setmealpagination.pageSize,//每页显示的记录数
                    queryString: this.setmealpagination.queryString//查询条件
                };
                //发送ajax请求 提交分页相关参数
                axios.post("/setmeal/findPage.do",param).then((res) => {
                    //为VUE对象的模型数据赋值,基于双向数据绑定展示到页面
                    this.setmealdataList = res.data.rows;//当前页展示的数据集合
                    this.setmealpagination.total = res.data.total;//总数据量
                });
            },
            // 重置表单
            resetForm() {
                this.formData = {};

            },
            // 弹出添加窗口
            handleCreate() {
                this.resetForm();
                this.dialogFormVisible = true;
                this.setmealpagination.queryString = null;
                //发送Ajax请求 查询所有的检查项信息 转为json
                this.activeName = 'first';
                //查询套餐数据
                this.setmealfindPage();
            },
            // 确认预约窗口
            handleUpdate(row) {
                //发送ajax请求 根据预约ID查询日期并发短信提醒用户
                axios.get("/ordersetting/confirm.do?id=" + row.id).then((res) => {
                    if (res.data.flag) {
                        //确认成功
                        this.$message({
                            type:'success',
                            message:res.data.message
                        });
                    } else {
                        //确认失败
                        this.$message.error(res.data.message);
                    }
                });
            },
            //预约切换页码
            handleCurrentChange(currentPage) {
                //为模型数据赋值(当前页面)
                this.pagination.currentPage = currentPage;
                this.findPage();
            },
            //套餐切换页码
            setmealhandleCurrentChange(currentPage) {
                //为模型数据赋值(当前页面)
                this.pagination.currentPage = currentPage;
                this.findPage();
            },
            // 取消预约
            handleDelete(row) {//row为一个json对象
                this.$confirm("您确定要取消预约么？","提示",{
                    type: 'warning'
                }).then(() => {
                    //用户点击确定按钮  发送ajax请求 将ID 提交给controller
                    axios.get("/ordersetting/delete.do?id=" + row.id).then((res) => {
                        if (res.data.flag) {
                            //执行成功
                            //弹出成功提示信息
                            this.$message({
                                type:'success',
                                message:res.data.message
                            });
                            //重新进行分页查询
                            this.findPage();
                        }else {
                            //执行失败
                            this.$message.error(res.data.message);
                        }
                    }).catch((r) => {
                        this.showMessage(r);

                    })
                }).catch(() => {
                    this.$message({
                        type:'info',
                        message:'操作已取消'
                    });
                });
            },
            //批量取消预约
            batchhandleDelete() {//row为一个json对象
                this.$confirm("您确定要取消预约么？","提示",{
                    type: 'warning'
                }).then(() => {
                    //用户点击确定按钮  发送ajax请求 将ID 提交给controller
                    axios.post("/ordersetting/batchdelete.do", this.orderIds).then((res) => {
                        if (res.data.flag) {
                            //执行成功
                            //弹出成功提示信息
                            this.$message({
                                type:'success',
                                message:res.data.message
                            });
                            //重新进行分页查询
                            this.findPage();
                        }else {
                            //执行失败
                            this.$message.error(res.data.message);
                        }
                    }).catch((r) => {
                        this.showMessage(r);

                    })
                }).catch(() => {
                    this.$message({
                        type:'info',
                        message:'操作已取消'
                    });
                });
            },
            //批量确认预约
            batchhandleUpdate(){
                //发送ajax请求 根据预约ID查询日期并发短信提醒用户
                axios.post("/ordersetting/batchconfirm.do", this.orderIds).then((res) => {
                    if (res.data.flag) {
                        //确认成功
                        this.$message({
                            type:'success',
                            message:res.data.message
                        });
                    } else {
                        //确认失败
                        this.$message.error(res.data.message);
                    }
                });
            },
            //将复选框选中的数据储存下来
            handleSelectionChange(val){
                this.orderIds = val;
            },
            //将套餐单选框中的数据储存下来
            setmealCurrentChange(val){
                this.setmealid = val.id;
            },
            handleReserve(row){
                return row.id
            },
            formatter(row, column) {
                return row.address;
            }
        }
    })
</script>
</html>
